09. Lesson Review

In this lesson we learned…

What is the profiler and how can we use it?

The profiler lets us explore our scene’s performance in a graphical way in real time.

To open the profiler, go to Window > Profiler. (Or Window > Analysis > Profiler.)

The CPU Usage is a big graph that’s color coded to represent different aspects of our application. Clicking on a name in the legend on the left of the graph will turn that specific item on or off.

The Overview section gives us a more detailed view of the scene that will show us which individual functions or scripts that are taking up a lot of processing power. Clicking on the name of a column will allow us to sort the data in the table. For example, if we expect that our CPU is the problem, we’d sort by “Total”. If we expect that graphics are an issue, we could sort by “Time ms”.

To use the profiler, we should start by looking for the biggest areas of the graph and investigate those first.

What kinds of things can we expect from the profiler?

Typically, we’ll be using the CPU Usage and Rendering sections of the graphs. We can expect that a lot of the overhead we see will be from rendering the data for two cameras (one for each lens) and the scripts responsible for detecting our movement in VR. Most of this overhead will be inside the Camera.Render function of the Overview table.

Additionally, the graph will adjust automatically to accommodate spikes in our app. This doesn’t have anything to do with our app specifically. It’s just making adjustments to the graph to make it easier to see.

Tip: Remember when we mentioned that running an app on the computer in the Unity editor and on our devices will generate different results? This can lead our profiler to give us some inaccurate information if we only use it to test our apps in the editor on a computer. See the next section for how to get profiler data from our devices.

Using the profiler in the Unity editor is great, but how can we get the information for the app as it’s running on our devices?

One way of doing this would be with a cable. With VR though, this isn’t always an ideal solution. Unity lets us stream our app’s data over WiFi to our computer through what’s called “Remote Profiling”.

In our build settings, select “Autoconnect Profiler” and “Development Build”. Be sure that your computer and your device are on the same WiFi network.

In the profiler, be sure that Active Profiler is selected.

Profiler top bar hovering over Active Profiler.

If you’re on a newer version of Unity, the Active Profiler button may have changed. Instead of saying Active Profiler, it’ll say Editor. Select the drop down to switch it to your device.

Editor dropdown shows devices to connect to.

Tip: Before publishing or sharing your app, be sure to turn off the Autoconnect Profiler and Development Build.